function SurveyViewModel(user, questions){
	var self = this;
	
	self.questions = questions;
	self.userId = user["id"];
	self.userName = user["name"];
	
	self.step = ko.observable(1);
	self.selectedQuestion = ko.observable(self.questions[0]);
	self.questionIndex = ko.observable(0);
	
	self.chosenOptions = ko.observableArray([]);
	
	self.nextStep = function(){
		self.step(self.step() + 1);
	};
	
	self.nextQuestion = function(option){
		self.chosenOptions.push(option.id);
		self.questionIndex(self.questionIndex() + 1);
		
		if(self.questionIndex() == self.questions.length){
			self.save();
			return;
		}
		
		self.selectedQuestion(self.questions[self.questionIndex()]);
	};
	
	self.save = function(){
		$.post(getCompletePath("survey/answer"), $.param({'id': self.chosenOptions(), 'userId': self.userId }, true),function(e) {
			self.nextStep();
		});
	};
	
	self.welcomeVisible = ko.computed(function(){
		return self.step() === 1;
	});
	
	self.questionsVisible = ko.computed(function(){
		return self.step() === 2;
	});
	
	self.thanksVisible = ko.computed(function(){
		return self.step() === 3;
	});
}

function Question(data){
	var self = this;
	self.id = data.id;
	self.description = ko.observable(data.description);
	self.option = ko.observable($.map(data.options, function(option){ return new Option(option); }));
}

function Option(data){
	var self = this;
	self.id = data.id;
	self.description = data.description;
}